package com.hgk.common.common.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

import com.common.nostra13.universalimageloader.core.DisplayImageOptions;
import com.common.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.common.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.common.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

/**
 * 图片加载统一参数设置工具类
 */
public class LoadImageDisplayOption {
	/**
	 * 加载大图
	 * @param ImageId
	 * @return
	 */
	public static DisplayImageOptions getDefaultPic(int ImageId){
		DisplayImageOptions displayImageOptionsPic=null;
		try {
		displayImageOptionsPic = new DisplayImageOptions.Builder()
//		.imageScaleType(ImageScaleType.EXACTLY)
		.cacheInMemory(true)
		.cacheOnDisc(true)
		.considerExifParams(true)
		.resetViewBeforeLoading(true)
		.showImageForEmptyUri(ImageId)
		.showImageOnLoading(ImageId)
		.showStubImage(ImageId)
		.showImageOnFail(ImageId)
		.build();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return displayImageOptionsPic;
	}
	public static DisplayImageOptions getRoundImageOptions(int ImageId){
        DisplayImageOptions displayImageOptionsPic=null;
        try {
            displayImageOptionsPic = new DisplayImageOptions.Builder()
                    .imageScaleType(ImageScaleType.EXACTLY)
                    .cacheInMemory(true)
                    .cacheOnDisc(true)
                    .considerExifParams(true)
                    .resetViewBeforeLoading(true)
                    .showImageForEmptyUri(ImageId)
                    .showImageOnLoading(ImageId)
                    .showStubImage(ImageId)
                    .showImageOnFail(ImageId)
                    .displayer(new RoundedBitmapDisplayer(20))
                    .build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return displayImageOptionsPic;
    }
	/**
	 * 加载大图（默认图传drawable）
	 * @param
	 * @return
	 */
	public static DisplayImageOptions getDefaultPicForDrable(int ImageId){
		DisplayImageOptions displayImageOptionsPic = new DisplayImageOptions.Builder()
		.showImageForEmptyUri(ImageId)
		.imageScaleType(ImageScaleType.EXACTLY)
		.bitmapConfig(Bitmap.Config.ARGB_8888)
		.cacheInMemory(true)  
		.cacheOnDisc(true)
		.considerExifParams(true)
		.resetViewBeforeLoading(true)
		.showImageOnLoading(ImageId)
		.showImageOnFail(ImageId)
		.build();
		return displayImageOptionsPic;
	}
	
	/**
	 * 加载icon
	 * @param ImageId
	 * @return
	 */
	public static DisplayImageOptions getDefaultIcon(int ImageId){
		DisplayImageOptions displayImageOptionsIcon = new DisplayImageOptions.Builder()
		.imageScaleType(ImageScaleType.EXACTLY)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.cacheInMemory(true)    
		.cacheOnDisc(true)
		.considerExifParams(true)
		.resetViewBeforeLoading(true)
		.showStubImage(ImageId)
		.showImageOnLoading(ImageId)
		.showImageForEmptyUri(ImageId)
		.build();
		return displayImageOptionsIcon;
	}

	/**
	 * 获取缓存路径
	 * 
	 * @param context
	 *            ：上下文
	 * @return：返回缓存路径，可能为null
	 */
	public static String getCacheDirectory(Context context) {
		return StorageUtils.getCacheDirectory(context).getAbsolutePath();
	}
	/**
	 * 获取缓存大小
	 * 
	 * @param context
	 * @return
	 */
	public static String getFileSize(Context context) {
		File f = StorageUtils.getCacheDirectory(context);
		try {
			return GetFileSizeUtil.getInstance().FormetFileSize(GetFileSizeUtil.getInstance().getFolderSize(f));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
}

